home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Panel Editor / Source / Printer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-08  |  7.4 KB  |  242 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Printer.h
  3.  
  4.     Contains:    Declaration of CPrinter class for OpenDoc printing utility
  5.  
  6.     Written by:    Steve Smith, Thomas Weisbach, Jens Alfke
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     Disclaimer:    This utility was added to the set of standard OpenDoc utilities
  11.                 somewhat at the last minute (it was previously part of the sample
  12.                 parts.) It hasn't been as extensively tested as the other utilities.
  13.                 Of course, all the utilities are supplied as-is.
  14. */
  15.  
  16. #ifndef _PRINTER_
  17. #define _PRINTER_
  18.  
  19. #ifndef _ODTYPES_
  20. #include <ODTypes.h>
  21. #endif
  22.  
  23.  
  24. //=================================================================================
  25. // Resource ID declarations:
  26. //
  27. //         Used by the DisplayError method. Clients don't need to use these resource
  28. //        IDs, but they need to be aware of them so they can provide the appropriate
  29. //        resources (or renumber the IDs if they prefer to use different numbering.)
  30. //=================================================================================
  31.  
  32. enum
  33. {
  34.     rPrintErrorsID = 32000,                // 'STR#' resource of printing error messages
  35.     
  36.     rMenuStrID = 32001,                    // 'STR#' resource of "Undo" / "Redo" strings
  37.          kPMUndoStrIndex = 1,                // Index of "Undo" string in rMenuStrID
  38.          kPMRedoStrIndex,                    // Index of "Redo" string in rMenuStrID
  39.          
  40.     rPrintErrorDialog = 32000            // 'ALRT' of printing-error alert
  41. };
  42.  
  43.  
  44. //=================================================================================
  45. // CPrinter
  46. //=================================================================================
  47.  
  48.  
  49. struct Environment;
  50. class ODFacet;
  51. class ODFrame;
  52. class ODSession;
  53. class ODShape;
  54. class ODStorageUnit;
  55.  
  56.  
  57. class CPrinter {
  58.  
  59.     public:
  60.     
  61.         // -- Factory method & destructor --
  62.         static CPrinter*    New( Environment*, ODStorageUnit* );
  63.         
  64.         virtual ~CPrinter();
  65.         
  66.         // -- Storage --
  67.                 void        Externalize( Environment*, ODStorageUnit* =kODNULL );
  68.     
  69.         // -- Getters --
  70.         virtual ODGraphicsSystem    GetGraphicsSystem( )                                =0;
  71.                 ODPlatformPrintJob    GetPlatformPrintJob( Environment* );
  72.         virtual ODRect                GetPageRect( Environment* )                            =0;
  73.     
  74.         // -- Printing --
  75.                 ODBoolean    PageSetup( Environment* );
  76.                 void        PrintDocument( Environment*, ODFrame* initiator, ODShape* area =kODNULL );
  77.     
  78.     protected:
  79.         // -- Private stuff --
  80.         CPrinter();
  81.     
  82.         virtual void        Initialize( Environment*, ODStorageUnit *su );
  83.         
  84.         virtual void        OpenPrinting( );
  85.         virtual void        ClosePrinting( );
  86.         inline    ODBoolean    IsPrintingOpen( )                                {return fPrintingOpen;}
  87.  
  88.         virtual ODValueType    GetValueType( )                                                =0;
  89.         virtual ODValueType    GetSecondaryValueType( )                        {return kODNULL;}
  90.         virtual ODPlatformPrintJob    BasicGetPlatformPrintJob( )                            =0;
  91.         virtual ODPlatformPrintJob    ReadJobFromHandle( ODValueType valueType, ODHandle)    =0;
  92.         virtual ODPlatformPrintJob    CreateNewJob()                                        =0;
  93.         virtual ODHandle    CopyJobToHandle( )                                            =0;
  94.         
  95.         virtual    void        SetupPrintingEnv( Environment*, ODFrame* initiator, ODShape *area );
  96.         virtual void        CleanupPrintingEnv( Environment*, ODFrame* initiator );
  97.         virtual ODPlatformCanvas CreatePrintingPlatformCanvas( Environment*, ODGraphicsSystem,
  98.                                             ODFrame *initiator, ODShape *area )             =0;
  99.         virtual ODULong        CountPages( Environment*, ODShape* area );
  100.  
  101.         virtual void        PrintPage( Environment*, ODUShort page, ODShape *area );
  102.         virtual void        SetPage( Environment*, ODUShort pageNum, ODShape* area );
  103.         
  104.         virtual void        OpenPage( Environment*, ODUShort page )                        =0;
  105.         virtual void        ClosePage( Environment* )                                    =0;
  106.         
  107.         virtual ODBoolean    RunPageSetupDialog( Environment *ev )                        =0;
  108.         virtual ODBoolean    RunPrintDialog( Environment *ev )                            =0;
  109.         virtual void        DoPrint( Environment*, ODShape* area )                        =0;
  110.         
  111.         virtual void        DisplayError( Environment*, ODSShort error );
  112.         
  113.         ODSession*            fSession;
  114.         ODStorageUnit*        fSU;
  115.         ODFacet*            fPrintFacet;
  116.         ODBoolean            fDirty;
  117.         ODSShort            fPrintingOpen;
  118.         
  119.         friend class CWithPrintingOpen;
  120. };
  121.  
  122.  
  123. //=================================================================================
  124. // Private stuff
  125. //=================================================================================
  126.  
  127. #ifdef _PRINTER_PRIVATE_
  128.  
  129. #ifndef __PRINTING__
  130. #include <Printing.h>        /* For THPrint and TPrPort */
  131. #endif
  132.  
  133. #ifndef __GXPRINTING__
  134. #include <GXPrinting.h>
  135. #endif
  136.  
  137. #ifndef __GXENVIRONMENT__
  138. #include <GXEnvironment.h>
  139. #endif
  140.  
  141. class ODWindowState;
  142.  
  143. //-----------------------------------------------
  144.  
  145. class CQDPrinter : public CPrinter {
  146.  
  147.     public:
  148.         CQDPrinter();
  149.         virtual ~CQDPrinter();
  150.             
  151.     protected:
  152.         virtual void        OpenPrinting( );
  153.         virtual void        ClosePrinting( );
  154.         virtual ODGraphicsSystem    GetGraphicsSystem( )            {return kODQuickDraw;}
  155.         virtual ODValueType    GetValueType( )                            {return kODTypeQuickDrawPageSetup;}
  156.         virtual ODPlatformPrintJob    BasicGetPlatformPrintJob( )        {return (ODPlatformPrintJob)fJob;}
  157.         virtual ODPlatformPrintJob    ReadJobFromHandle( ODValueType valueType, ODHandle );
  158.         virtual ODPlatformPrintJob    CreateNewJob();
  159.         virtual ODHandle    CopyJobToHandle( );
  160.         virtual ODPlatformCanvas CreatePrintingPlatformCanvas( Environment*, ODGraphicsSystem,
  161.                                             ODFrame *initiator, ODShape *area );
  162.         virtual ODRect        GetPageRect( Environment* );
  163.         virtual void        CleanupPrintingEnv( Environment*, ODFrame* initiator );
  164.         virtual void        OpenPage( Environment*, ODUShort page );
  165.         virtual void        ClosePage( Environment* );
  166.         virtual ODBoolean    RunPageSetupDialog( Environment *ev );
  167.         virtual ODBoolean    RunPrintDialog( Environment *ev );
  168.         virtual void        DoPrint( Environment*, ODShape* area );
  169.     
  170.     private:
  171.         THPrint        fJob;
  172.         TPrPort*    fPort;
  173.         Ptr            fIOBuffer;
  174.         ODBoolean    fPageOpen;
  175. };
  176.  
  177. //-----------------------------------------------
  178.  
  179. class CGXPrinter : public CPrinter {
  180.  
  181.     public:
  182.         CGXPrinter();
  183.         virtual ~CGXPrinter();
  184.  
  185.     protected:
  186.         virtual void        Initialize( Environment*, ODStorageUnit *su );
  187.         virtual ODGraphicsSystem    GetGraphicsSystem( )            {return kODQuickDrawGX;}
  188.         virtual ODValueType    GetValueType( )                            {return kODTypeGXPageSetup;}
  189.         virtual ODValueType    GetSecondaryValueType( )                {return kODTypeQuickDrawPageSetup;}
  190.         virtual ODPlatformPrintJob    BasicGetPlatformPrintJob( )        {return (ODPlatformPrintJob)fJob;}
  191.         virtual ODPlatformPrintJob    ReadJobFromHandle( ODValueType valueType, ODHandle );
  192.         virtual ODPlatformPrintJob    CreateNewJob();
  193.         virtual ODHandle    CopyJobToHandle( );
  194.         virtual ODPlatformCanvas CreatePrintingPlatformCanvas( Environment*, ODGraphicsSystem,
  195.                                             ODFrame *initiator, ODShape *area );
  196.         virtual ODRect        GetPageRect( Environment* );
  197.         virtual void        CleanupPrintingEnv( Environment*, ODFrame* initiator );
  198.         virtual void        OpenPage( Environment*, ODUShort page );
  199.         virtual void        ClosePage( Environment* );
  200.         virtual ODBoolean    RunPageSetupDialog( Environment *ev );
  201.         virtual ODBoolean    RunPrintDialog( Environment *ev );
  202.         virtual void        DoPrint( Environment*, ODShape* area );
  203.         
  204.                 void        EnableMenus( Environment*, ODBoolean enable );
  205.         
  206.         static    OSErr        PrintAShape( gxShape currentShape, long refCon );
  207.  
  208.     private:
  209.         gxJob            fJob;
  210.         gxViewPort        fViewPort;
  211.         GrafPtr            fQDPort;
  212.         gxEditMenuRecord fEditMenuRec;
  213.         gxShapeSpoolUPP    fPrintAShapeProcPtr;
  214.         ODBoolean        fJobStarted;
  215.         ODBoolean        fPageOpen;
  216. };
  217.  
  218. class CWithPrintingOpen :Destructo
  219. {
  220.     public:
  221.         CWithPrintingOpen( CPrinter* );
  222.         ~CWithPrintingOpen( );
  223.     private:
  224.         CPrinter *fPrinter;
  225. };
  226.  
  227. class CWithDialogState :Destructo
  228. {
  229.     public:
  230.         CWithDialogState( Environment *ev, ODSession *session );
  231.         ~CWithDialogState( );
  232.     private:
  233.         Environment *fEv;
  234.         ODWindowState *fWindowState;
  235. };
  236.  
  237. void BusyCursor( );
  238.  
  239. #endif /*_PRINTER_PRIVATE_*/
  240.  
  241. #endif /*_PRINTER_*/
  242.